package io;

import java.io.*;
import java.util.Scanner;

/**
 * 实现简易记事本工具
 * 程序启动后，要求用户输入一个文件名，然后对该文件写操作
 * 之后用户输入的每一行字符串都能按行写入到该文件中
 * 当用户单独输入exit时程序退出
 *
 */
public class Test2 {
    public static void main(String[] args) throws FileNotFoundException, UnsupportedEncodingException {
        Scanner scan = new Scanner(System.in);
        String name = scan.nextLine();
        FileOutputStream fos = new FileOutputStream(name);
        OutputStreamWriter osw = new OutputStreamWriter(fos,"UTF-8");
        BufferedWriter bos = new BufferedWriter(osw);
        PrintWriter pw = new PrintWriter(bos);
        String line = "exit";
        while(true){
            String aa = scan.nextLine();
            if(aa.equals(line)){
                break;
            }else{
                pw.println(aa);
            }
        }
        pw.close();


    }
}
